package com.yequan.designpattern.singleton.EnumFactory;

/**
 * @Auther: yq
 * @Date: 2019/1/11 12:51
 * @Description:
 */
public enum EnumUnSingleFactory {

    /**
     * 枚举数据类型实现单例模式（线程安全）
     * 这种方式暴露了枚举类，违反单一职责原则
     */
    singletonFactory;

    private EnumSingleton instance;

    private EnumUnSingleFactory() {
        try {
            Thread.sleep(300);
            instance = new EnumSingleton();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public EnumSingleton getInstance() {
        return instance;
    }

}

class EnumSingleton {
    public EnumSingleton() {
    }
}
